﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.LCM
{
    public class MathHelper
    {
        public static List<long> GetPrimes(long n)
        {
            List<long> primes = new List<long>();
            if (n < 2)
                return primes;

            primes.Add(2);
            for (long i = 3; i <= n; i+=2)
            {
                // 3, 5, 7, 11, 13, 17, 19, 23, 29...
                bool maybePrime = true;
                foreach(long prime in primes)
                //for (long j = 2; j <= i / 2 && maybePrime; j++)
                {
                    if (i % prime == 0)
                    //if (i % j == 0)
                    {
                        //continue acts on inner for, not outer
                        maybePrime = false;
                    }
                }
                if (maybePrime)
                    primes.Add(i);
            }
            return primes;
        }
    }
}
